import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import finalRoutes from "@/router/permissionRoutes";
import store from "./store";
import VueCookies from "vue-cookies";
import Cookies from "js-cookie"
import $ from 'jquery'
//引入 element-ui
import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
//引入 i-view
import ViewUI from "view-design";
import "view-design/dist/styles/iview.css";
//引入 vxe-table
import "xe-utils";
import VXETable from "vxe-table";
import "vxe-table/lib/style.css";
//引入lodash
import _ from "lodash";
import * as echarts from "echarts";
import XEUtils from "xe-utils";
import "@/assets/css/reset.css";
import "@/assets/iconfont/iconfont.css";

require("./mock/index");

Vue.config.productionTip = false;

Vue.use(VueCookies);
Vue.use(ElementUI);
Vue.use(ViewUI);
Vue.use(VXETable);
Vue.use(_);
Vue.use(XEUtils);
//使用jquery(this.$(''))
Vue.prototype.$ = $
Vue.prototype.$echarts = echarts;
finalRoutes.forEach(route => router.addRoute(route))
router.beforeEach((to, from, next) => {
  const csrftoken = Cookies.get('csrftoken')
  if (to.path === "/login") {
    localStorage.clear();
  } else {
    if (!csrftoken) {
      next("/login");
    }
  }
  // 路由跳转之前，中止还在等待的请求
  const axiosCancels = store.state.axiosCancels;
  if (axiosCancels.length) {
    axiosCancels.forEach(cancel => cancel && cancel());
    store.commit("SET_AXIOS_CANCELS", []);
  }
  next();
});
new Vue({
  beforeCreate() {
    Vue.prototype.$bus = this;
  },
  router,
  store,
  render: (h) => h(App)
}).$mount("#app");
